package com.xyh.flowershop.service.impl;


import com.xyh.flowershop.enums.LoginEnum;
import com.xyh.flowershop.service.LoginService;
import com.xyh.flowershop.strategy.AbstractLogin;
import com.xyh.flowershop.vo.req.user.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.xyh.flowershop.strategy.AbstractLogin.strategyMap;


/**
 * @author 小约翰可汗
 * @className LoginServiceImpl
 * @createTime 2024/4/1621:14
 */
@Slf4j
@Service("loginServiceImp")
@Transactional(rollbackFor = RuntimeException.class)
public class LoginServiceImpl implements LoginService {

    @Override
    public String login(LoginUser loginUser) {
        LoginEnum loginEnum = LoginEnum.fromLoginType(loginUser.getLoginType());
        AbstractLogin login = strategyMap.get(loginEnum.getCode());
        log.info("登录类型：{}", loginEnum.getCode());
        String token = login.login(loginUser);
        return token;
    }
}
